import { _decorator, v3, Vec2, Vec3 } from "cc";
import { BattleObj } from "./BattleObj";
const { ccclass, property } = _decorator;

@ccclass("EnemyObj")
export class EnemyObj extends BattleObj {
    targetPos: Vec3 = v3(0, 0, 0);
    speed: number = 100;
    public tick(dt: number): void {
        this.moveCheck(dt);
    }
    moveCheck(dt: number) {
        {
            if (this.target == null || this.target.isDie()) {
                return;
            }
            this.target.node.getPosition(this.targetPos);
            if (Vec2.distance(this.node.position, this.targetPos) < 5) {
                return
            }
            let dir = this.targetPos.clone().subtract(this.node.position).normalize();
            this.moveDirecion.set(dir.x, dir.y);
            let move = dir.multiplyScalar(this.speed * dt);
            this.node.setPosition(this.node.position.add(move));
        }
    }
}